package com.qf.rabbit.simple;

import com.qf.rabbit.utils.ConnectionUtil;
import com.rabbitmq.client.*;

import java.io.IOException;
import java.util.concurrent.TimeoutException;

public class Consumer {

    public static void main(String[] args) throws IOException, TimeoutException {
        Connection connection = ConnectionUtil.getConnection();
        Channel channel = connection.createChannel();
        //生产者和消费者声明队列的时候必须使用一模一样的参数, 有一个不一样都不行
        channel.queueDeclare("bk2105", true, false, false, null);
        //消费消息, autoack 自动应答
        channel.basicConsume("bk2105", true,new DefaultConsumer(channel){

            @Override
            public void handleDelivery(String consumerTag, Envelope envelope, AMQP.BasicProperties properties, byte[] body) throws IOException {
                System.err.println("消费者 22222 收到了:"+new String(body));
            }
        });
    }
}
